package com.ruoyi.service.controller;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.service.utils.ServiceUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.Assume;
import com.ruoyi.service.service.IAssumeService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;

/**
 * 假设执行政府定价 信息操作处理
 *
 * @author john
 * @date 2019-01-04
 */
@Controller
@RequestMapping("/service/assume")
public class AssumeController extends BaseController {
    private String prefix = "service/assume";

    @Autowired
    private IAssumeService assumeService;
    @Autowired
    private ServiceUtils utils;

    @GetMapping()
    public String assume() {
        return prefix + "/assume";
    }

    /**
     * 查询假设执行政府定价列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Assume assume) {
        startPage();
        List<Assume> list = assumeService.selectAssumeList(assume);
        return getDataTable(list);
    }


    /**
     * 导出假设执行政府定价列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Assume assume) {
        List<Assume> list = assumeService.selectAssumeList(assume);
        ExcelUtil<Assume> util = new ExcelUtil<Assume>(Assume.class);
        return util.exportExcel(list, "assume");
    }

    /**
     * 新增假设执行政府定价
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存假设执行政府定价
     */
    @Log(title = "假设执行政府定价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Assume assume) {
        return toAjax(assumeService.insertAssume(assume));
    }

    /**
     * 修改假设执行政府定价
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        Assume assume = assumeService.selectAssumeById(id);
        mmap.put("assume", assume);
        return prefix + "/edit";
    }

    /**
     * 修改保存假设执行政府定价
     */
    @Log(title = "假设执行政府定价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Assume assume) {
//		录入项：getPPP()
        BigDecimal ffp = assume.getPPP().multiply(BigDecimal.valueOf(0.95 * 1.5));
        BigDecimal fpp = assume.getPPP().multiply(BigDecimal.valueOf(0.95));
        BigDecimal fgp = assume.getPPP().multiply(BigDecimal.valueOf(0.95 * 0.5));
        BigDecimal fTotalP = assume.getPPP().multiply(BigDecimal.valueOf(0.95 * 3));

        BigDecimal pfP = assume.getPPP().multiply(BigDecimal.valueOf(1.5));
        BigDecimal pgP = assume.getPPP().multiply(BigDecimal.valueOf(0.5));
        BigDecimal pTotalP = assume.getPPP().multiply(BigDecimal.valueOf(3));

        BigDecimal kFP = assume.getPPP().multiply(BigDecimal.valueOf(1.05 * 1.5));
        BigDecimal kPP = assume.getPPP().multiply(BigDecimal.valueOf(1.05));
        BigDecimal kGP = assume.getPPP().multiply(BigDecimal.valueOf(1.05 * 0.5));
        BigDecimal kTotalP = assume.getPPP().multiply(BigDecimal.valueOf(1.05 * 3));

        assume.setFFP(ffp);
        assume.setFPP(fpp);
        assume.setFGP(fgp);
        assume.setFTotalP(fTotalP);
        assume.setPFP(pfP);
        assume.setPGP(pgP);
        assume.setPTotalP(pTotalP);
        assume.setKFP(kFP);
        assume.setKPP(kPP);
        assume.setKGP(kGP);
        assume.setKTotalP(kTotalP);
        int i = assumeService.updateAssume(assume);
        utils.total(assume.getPointId(), assume.getBasicsId());
        return toAjax(i);
    }

    /**
     * 删除假设执行政府定价
     */
    @Log(title = "假设执行政府定价", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(assumeService.deleteAssumeByIds(ids));
    }

}
